package net.mikoo.seals.api.model.install;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import net.mikoo.seals.api.model.BaseResponse;
import net.mikoo.seals.common.enums.InstallTypeEnum;
import net.mikoo.seals.common.model.PageModel;
import net.mikoo.seals.model.Install;

public class InstallVerifyListResponse extends BaseResponse {

	private List<VerifyInfo> verifys;
	
	public List<VerifyInfo> getVerifys() {
		return verifys;
	}

	public void setVerifys(List<VerifyInfo> verifys) {
		this.verifys = verifys;
	}

	public void setData(PageModel<Install> pm) {
		if(pm == null || pm.getDatas() == null || pm.getDatas().isEmpty()) {
			return ;
		}
		
		this.verifys = new ArrayList<VerifyInfo>();
		for(Install install : pm.getDatas()) {
			if(install == null || install.getInstallId() == null) {
				continue;
			}
			
			VerifyInfo verify = new VerifyInfo();
			verify.setId(install.getInstallId());
			
			InstallTypeEnum type = InstallTypeEnum.getByCode(install.getInstallType());
			if(type != null) {
				verify.setType(type.getCode());
				verify.setTypeName(type.getMessage());
			}
			if(install.getSeal() != null) {
				verify.setSealName(install.getSeal().getSealName());
			}
			
			verify.setApplyTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(install.getApplyTime()));
			
			if(install.getPerson() != null) {
				verify.setPartyName(install.getPerson().getName());
			}
			this.verifys.add(verify);
		}
	}


	class VerifyInfo {
		
		private Long id;
		
		private String type;
		
		private String typeName;
		
		private String sealName;
		
		private String applyTime;
		
		private String partyName;

		public Long getId() {
			return id;
		}

		public void setId(Long id) {
			this.id = id;
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public String getTypeName() {
			return typeName;
		}

		public void setTypeName(String typeName) {
			this.typeName = typeName;
		}

		public String getSealName() {
			return sealName;
		}

		public void setSealName(String sealName) {
			this.sealName = sealName;
		}

		public String getApplyTime() {
			return applyTime;
		}

		public void setApplyTime(String applyTime) {
			this.applyTime = applyTime;
		}

		public String getPartyName() {
			return partyName;
		}

		public void setPartyName(String partyName) {
			this.partyName = partyName;
		}
	}
}
